home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 February: Tool Chest / Dev.CD Feb 99 TC.toast / What's New? / Development Kits / Mac OS USB v1.1f3 DDK / Examples / PrinterClassDriver / MissingLibraryRoutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.3 KB  |  94 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MissingLibraryRoutines.c
  3.  
  4.     Contains:    Implementation of routines missing from InterfaceLib.
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Written by:    Quinn "The Eskimo!"
  9.  
  10.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  11.  
  12. */
  13.  
  14. #include <Types.h>
  15. #ifndef __MIXEDMODE__
  16. #include <mixedmode.h>
  17. #endif
  18. #ifndef __DEVICES__
  19. #include <devices.h>
  20. #endif
  21.  
  22. // This file contains implementations of various Mac OS API routines
  23. // that were never rolled in to InterfaceLib.  As a result, these
  24. // routines can be called from classic 68K clients, but not from
  25. // CFM-68K or CFM-PPC clients.
  26.  
  27. extern pascal SInt16 LMGetUnitTableEntryCount(void);
  28. extern pascal void LMSetUnitTableEntryCount(SInt16 value);
  29.  
  30. extern pascal SInt16 LMGetUnitTableEntryCount(void)
  31.     // Get the value from low memory directly.
  32. {
  33.     return *((SInt16 *) 0x01d2);
  34. }
  35.  
  36. extern pascal void LMSetUnitTableEntryCount(SInt16 value)
  37.     // Put the value into low memory directly.
  38. {
  39.     *((SInt16 *) 0x01d2) = value;
  40. }
  41.  
  42. // DriverInstallReserveMem is a bit trickier to implement that the
  43. // previous two routines.  Basically we have get the address of the
  44. // _DriverInstall ($A03D) trap and then call it using
  45. // CallOSTrapUniversalProc.  There are a number of important things
  46. // to note here:
  47. //   a) We can just get the trap address and treat it as a UPP.
  48. //      The trap tables are defined to contain UPPs, either pointers
  49. //      to real 68K code, or pointers to a routine descriptor (if
  50. //      the trap is native or fat).
  51. //   b) We must use CallOSTrapUniversalProc, not CallUniversalProc.
  52. //      CallOSTrapUniversalProc automatically does a number of things 
  53. //      that are very critical for call OS traps.  See "IM:PowerPC
  54. //      System Software", p2-42 for a full description.
  55. //   c) When calling OS traps from PPC, it's important to get the
  56. //      ProcInfo right.  Specifically, all OS traps assume an
  57. //      implicit parameter of D1 as the first parameter.  After
  58. //      that, the parameters should be defined in the order that
  59. //      they are declared in the prototype.  If you fail to get
  60. //      the order right, or to put D1 first, your code will work,
  61. //      up until it encounters someone who has patched the OS trap
  62. //      with a native or fat patch.  Then strange things will happen,
  63. //      and you'll spend hours in MacsBug trying to figure it out.
  64.  
  65. // The trap number and ProcInfo description for DriverInstallReserveMem.
  66.  
  67. enum {
  68.     _DriverInstallReserveMem = 0x0A43D
  69. };
  70.  
  71. enum {
  72.     uppDriverInstallProcInfo = kRegisterBased
  73.         | REGISTER_RESULT_LOCATION(kRegisterD0)
  74.         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  75.         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(short)))
  76.         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(DRVRHeaderPtr)))
  77.         | REGISTER_ROUTINE_PARAMETER(3, kRegisterD0, SIZE_CODE(sizeof(short)))
  78. };
  79.  
  80. extern pascal OSErr DriverInstallReserveMem(DRVRHeaderPtr drvrPtr, short refNum)
  81. {
  82.     UniversalProcPtr trapAddress;
  83.     
  84.     // Check that I've got the ProcInfo correct.
  85.     if (false) {
  86.         if ( uppDriverInstallProcInfo != 0x00533022) {
  87.             DebugStr("\pDriverInstallReserveMem: uppDriverInstallProcInfo is not what it should be.");
  88.         }
  89.     }
  90.     
  91.     trapAddress = (UniversalProcPtr) GetOSTrapAddress(_DriverInstallReserveMem);
  92.     return CallOSTrapUniversalProc(trapAddress, uppDriverInstallProcInfo, _DriverInstallReserveMem, drvrPtr, refNum);
  93. }
  94.